<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		div{width: 300px;height: 200px;border:1px solid #ccc;}
		.active{background: #e63131;}
	</style>
</head>
<body>
<div id="app">
	<div v-bind:class="{active:isActive}"></div>
	<button @click="toggleColor">切换底色</button>
	<ul>
		<li v-for="(value, key, index) of object">{{ index }}：{{ value }}-{{ key }}</li>
	</ul>
	<ul>
		<li v-for="(item, index) of items">{{ item.message }}-{{ index }}</li>
	</ul>
	<p>The button above has been clicked {{ counter }} times.</p>
  	<button @click="greet">Add 1</button>
  	<p>多个复选框，绑定到同一个数组</p>
	<label><input type="checkbox" v-model="checkNames" value="Jack">Jack</label>
	<label><input type="checkbox" v-model="checkNames" value="John">John</label>
	<label><input type="checkbox" v-model="checkNames" value="Mike">Mike</label>
	<p>Checked names: {{ checkNames }}</p>
	<p>单选按钮，绑定到同一个数组</p>
	<label><input type="radio" v-model="picked" value="one">one</label>
	<label><input type="radio" v-model="picked" value="two">two</label>
	<p>Checked names: {{ picked }}</p>
	<p>用 v-for 渲染的动态选项</p>
	<select v-model="selected">
		<option v-for="option of options" v-bind:value="option.value">{{ option.text }}</option>
	</select>
	<p>selected: {{ selected }}</p>
</div>
<script src="node_modules/vue/dist/vue.min.js"></script>	
<script>
var app = new Vue({
	el:'#app',
	data:{
		isActive:false,
		counter: 0,
		checkNames:[],
		picked:'',
		object: {
      		firstName: 'John',
      		lastName: 'Doe',
      		age: 30
    	},
    	items: [
      		{ message: 'Foo' },
      		{ message: 'Bar' }
    	],
    	selected: 'A',
    	options: [
      		{ text: 'One', value: 'A' },
      		{ text: 'Two', value: 'B' },
      		{ text: 'Three', value: 'C' }
    	]
	},
	methods:{
		toggleColor(){
			this.isActive = this.isActive?false:true
		},
		greet(event){
			this.counter+=1
			alert('hello' + this.object.firstName)
			if (event) {
				alert(event.target.tagName)
			}
		}
	}
})
</script>
</body>
</html>